/*
 * Copyright © 2017 eqxiu.com 北京中网易企秀科技有限公司  All rights reserved.
 */
package cn.hermit.data.json.model;

import cn.hermit.data.json.JSON;
import cn.hermit.util.StringUtils;

/**
 * Java Model of JSON Value
 * 
 * @author Jack Gao (Chinese name : GAO JIANGUO, Email : linux.gjg@gmail.com)
 * @date 13 Jun, 2014
 */
public class JSONValue extends JSONDocument {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6388571512948059078L;

	Object value;

	boolean isText;

	JSONValue() {

	}

	/**
	 * Get real Java Object from JSON Value.
	 * @return 
	 * 		Real Java Object
	 */
	public Object getValue() {
		if (value == null) {
			value = JSON.DEFAULT_NULL_VALUE;
		}
		return value;
	}

	/**
	 * Check if the JSON Value is string type 
	 * @return
	 */
	public boolean isText() {
		if (value == null) {
			isText = false;
		}
		return isText;
	}

	/**
     * Serialize JSON Value to JSON string
     */
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(getValue().toString());
		return sb.toString();
	}

	@Override
	String toFormatString(int depth, String newLineFeed, boolean isTop) {
		if (isTop) {
			return StringUtils.tabs(depth) + toString();
		}
		return toString();
	}
	
	@Override
    public boolean isArray() {
        return false;
    }

    @Override
    public boolean isObject() {
        return false;
    }

    @Override
    public boolean isValue() {
        return true;
    }

    @Override
    public boolean isTextValue() {
        return isText();
    }

}